package com.xioaye.cs.basic;

import java.util.ArrayList;
import java.util.Stack;

public class Lianbiao {
    public static void main(String[] args) {


    }


    public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {


        Stack<Integer> temp = new Stack<>();
        ArrayList<Integer> newList = new ArrayList<>();
        ListNode t = listNode;

        while (t != null) {

            temp.push(t.val);
            t = t.next;
        }
        while (!temp.empty()) {
            newList.add(temp.pop());
        }
        return newList;

    }


    public class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }

}